clear
capture log close
set more off
set mem 500m


****

use data_pt_pop_1891, clear

*** Fix manchester and salford
replace loc="manchester" if loc=="salford"
count
collapse (sum) pop, by(loc year)
count

sort loc
merge loc using data_town_cotton_shr_1851
tab _merge
keep if _merge==3
drop _merge


** LHS var
gen log_pop=log(pop)


** Identify city types
gen type="other"
replace type="cotton" if shr_cot>.1

replace shr_wool=0 if shr_wool==.
gen shr_tex = shr_wool + shr_other_tex
replace type="other_tex" if shr_tex>.1 & shr_cot<.1

tab loc if type=="cotton"
tab loc if type=="other_tex"
tab loc if type=="other"


**** Collapse and Reshape by type
collapse (sum) pop log_pop, by(type year)

reshape wide pop log_pop, i(year) j(type) string


gen lp_cot41=0
replace lp_cot41=log_popcotton if year==1861
egen lpcot=max(lp_cot41)
gen lpop_cot=log_popcotton-lpcot
drop lp_cot41 lpcot

gen lp_tex41=0
replace lp_tex41=log_popother_tex if year==1861
egen lptex=max(lp_tex41)
gen lpop_tex=log_popother_tex-lptex
drop lp_tex41 lptex

gen lp_oth41=0
replace lp_oth41=log_popother if year==1861
egen lpoth=max(lp_oth41)
gen lpop_oth=log_popother-lpoth
drop lp_oth41 lpoth

outsheet using results_figure_3_data.csv, comma names replace 



****
